#include "MatrixSVD.h"


MatrixSVD::MatrixSVD(string pFolder)
{
	
 string pathSTrans;
 multiplique=false;
 s=new Matrix("./fileAux/aux.S","read");
 t=new Matrix("./fileAux/aux.U","read");
 result=new Matrix("./Archivos/"+pFolder+"/sxt.txt","write");
 pathSTrans=s->transpose();
 delete s;
 system("rm ./fileAux/aux.S");
 sTrans=new Matrix(pathSTrans,"read");
}


MatrixSVD::~MatrixSVD()
{
	if(!multiplique)
	{
	 delete t;
	 delete sTrans;
	 delete result;
	}
}

void MatrixSVD::generateTxS(string repositorio)
{
 vector<double> myRow;

 sTrans->nextRow();

 while (!t->wasLast())
 {
  vector<double> aux;
  myRow.clear();
  t->nextRow();
  t->getRow(&myRow);
  for(unsigned int i=0; i<myRow.size();i++)
	  aux.push_back((1/sTrans->getColum(i))* myRow[i]);
  result->saveRow(aux);
 }

 delete t;
 delete sTrans;
 system("rm ./fileAux/aux.U");
 system("rm ./fileAux/aux.S.trans");
 delete result;
 //result=new Matrix("./Archivos/"+repositorio+"/sxt.txt","read");
 //result->transpose();
 //delete result;
 multiplique=true;
 //string file="rm  ./Archivos/"+repositorio+"/sxt.txt";
 //system(file.c_str());
 //Matrix *D=new Matrix("./Archivos/"+repositorio+"/D.txt","read");
 //D->transpose();
 //delete D;



}

